<!DOCTYPE html>
<html ng-app="myApp">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../css/index.css" />
		<link rel="stylesheet" type="text/css" href="../sass/loginPage.css" />
		<script type="text/javascript" src="../js/angular.js"></script>
		<script type="text/javascript" src="../js/jquery.min.js"></script>

		<title>登陆</title>
	</head>

	<body ng-controller="loginCtrl">
		<!--登陆页面-->

		<div id="loginPage">
			<div class="scroller">
				<div class="content">

					<img class="avatorImg" src="../img/shop.png" />

					<form action="" method="post">

						<table border="0" width="100%" cellpadding="0" cellspacing="0">
							<tr>
								<td class="hasMargin">手机号码</td>
								<td><input ng-model="phoneNumber" class="numInput" type="tel" placeholder="请输入11位手机号码" /></td>
							</tr>
							<tr>
								<td class="hasMargin">验证码</td>
								<td class="send"><input ng-model="vaildCode" class="vaildInpit" type="text" /><span class="sendMsg" ng-click="sendMsg()">点击发送</span></td>
							</tr>
						</table>
					</form>

					<div class="login" ng-click="toLogin()">
						登陆
					</div>

				</div>
			</div>
		</div>

	</body>

</html>
<script type="text/javascript">
	 var myApp = angular.module('myApp', []);
	 myApp.controller("loginCtrl",function($scope,$http){
	 	$("form").submit(function(e) {
				e.preventDefault();
			});
			// var isWeChatAccount=localStorage.getItem('isWeChatAccount');
			// if (isWeChatAccount) {
			// 	$scope.isWeChatAccount=true;
			// } else{
			// 	$scope.isWeChatAccount=false;
			// }


			$scope.phoneNumber="";
			$scope.vaildCode="";

			$scope.sendMsg = function() {
				//	 	alert(123);
				var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
				var phoneNum = $(".numInput").val();
				var sendMsg = $(".sendMsg");
				var countdown = 60;
				var login=$(".login");

				if(!myreg.test(phoneNum)) {
					alert('请输入有效的手机号码');
					return false;
				} else {
					//号码正确，发送验证码
					
						$http({
							url:"",
							method:"GET",
							parama:{'number':phoneNum}
						}).success(function(response){
	//						console.log(response);
						});

					settime(sendMsg);
					
					

				}
				//倒计时
				function settime(obj) {
					if(countdown == 0) {
						obj.removeClass("sendMsgOff").addClass("sendMsg");
						login.removeClass("loginOn").addClass("login");
						obj.text("点击发送");
						countdown = 60;
						
						return;
					} else {
						obj.removeClass("sendMsg").addClass("sendMsgOff");
						login.removeClass("login").addClass("loginOn");
						obj.text("重新发送" + countdown + "s");
						countdown--;
						console.log(countdown);

					}
					setTimeout(function() {
						settime(obj);
					}, 1000);
				}

			};
			//登陆
			$scope.toLogin=function(){
				var login=$(".login");

				var datas={'vaildCode':$scope.vaildCode,'phoneNumber':$scope.phoneNumber};
				console.log(datas);
				if (datas.vaildCode && datas.phoneNumber) {
					console.log("成功");
					window.location.href="../index.html?phoneNumber="+$scope.phoneNumber;
					// localStorage.setItem("isWeChatAccount",$scope.phoneNumber);
					// $scope.isWeChatAccount=!$scope.isWeChatAccount;

//					$http({
//						url:"",
//						method:"GET",
//						parama:{'number':phoneNum}
//					}).success(function(response){
//						console.log(response)
//					});


				}else{
					alert("登陆失败");
				}

			};
	 	
	 	
	 	
	 })
	
	
	
	
</script>